#!/bin/bash

if [ "$1" == "arm" ]
then
	ARCH=arm
	CROSS_COMPILE=arm-linux-gnueabi-
elif [ "$1" == "arm64" ]
then
	ARCH=arm64
	CROSS_COMPILE=aarch64-linux-gnu-
else
	echo "unkonw argument"
	exit 1
fi

cd linux
export ARCH=${ARCH}
export CROSS_COMPILE=${CROSS_COMPILE}

make distclean

if [ "$ARCH" == "arm" ]
then
git checkout arch/arm/configs/vexpress_defconfig
make vexpress_defconfig
cp arch/arm/configs/vexpress_defconfig ../tools/config/arm
cp .config ../tools/config/arm/vexpress_config
cp ../tools/config/arm/my_vexpress_defconfig arch/arm/configs
make my_vexpress_defconfig
cp .config ../tools/config/arm/my_vexpress_config
make -j4 zImage modules
mkdir -p .modules
make modules_install INSTALL_MOD_PATH=.modules
make dtbs
../tools/collect-src -f "linux" -o ../linux_arm.list
else
git checkout arch/arm64/configs/defconfig
make defconfig
cp arch/arm64/configs/defconfig ../tools/config/arm64/defconfig
cp .config ../tools/config/arm64/config
cp ../tools/config/arm64/my_defconfig arch/arm64/configs
make my_defconfig
cp .config ../tools/config/arm64/my_config
make -j4 
#make modules
#mkdir -p .modules
#make modules_install INSTALL_MOD_PATH=.modules
../tools/collect-src -f "linux" -o ../linux_arm64.list
fi

cd ..